/* TODO未完 */
import echarts from 'echarts'
import chart from '@/utils/chart.js'
import { toYYYYMMDD, toHHMM, toMMDD, formatTimeStamp } from '@/utils/timeUtil'
import {
  format
} from 'silly-datetime'
// import { parseNumFloat } from '@/utils/tool'
// import { keyToZh, valToZh } from './codeMaps.js'

export const chartTemHum = (chartData) => {
  const temData = []
  const humData = []
  const xAxisData = []
  chartData.forEach(item => {
    temData.push(item.data.tem)
    humData.push(item.data.hum)
    xAxisData.push(format(item.upload, 'HH:mm:ss'))
  })
  let option = {
    // legend: {
    //   data: ['设定温度', '房间温度'],
    //   selected: legendSelected,
    //   ...chart.DETAIL_LEGEND
    // },
    // grid: chart.DETAIL_GRID,
    legend:{
      tooltip:{
          // show:true
      },
      icon: "circle",
      x:'right',
      padding:[30, 80,0 ,0],
      data: ["温度","湿度"],
      textStyle: { color: "#F1F2F4" },
    },
    grid: {
      left: '2%',
      right: '2%',
      bottom: '3%',
      containLabel: true
    },
    tooltip:{
      trigger: 'axis'
    },
    dataZoom: [
      {
        type: 'inside',
        throttle: 50
      }
    ],
    xAxis: {
      type: 'category',
      // ...xAxisConfig,
      data:xAxisData,
      axisLine: {
        show: true,
        lineStyle: {
          color: '#6E798B'
        }
      },
      axisLabel: {
        show: true,
        interval: 5,
        color: '#F1F2F4',
        showMinLabel: true,
        showMaxLabel: true,
        formatter: (value, index) => {
          let t = value.substr(0, 5)
          return ` ${t}`
        }
      },
      splitLine: {
        show: false
      },
      axisTick:{
        show:false
      }
    },
    yAxis:[
      {
        name: '°C',
        type: 'value',
        ...chart.AXIS_STYLE
      },
      {
        name: '%RH',
        type: 'value',
        ...chart.AXIS_STYLE
      },
    ],
    series: [
      {
        smooth: true,
        symbol: 'none',
        sampling: 'average',
        name: '温度',
        type: 'line',
        data: temData,
        color: '#8DBAF3',
        lineStyle: {
          color: '#8DBAF3',
          width: 2
        },
        areaStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#8DB7F1" },
              { offset: 0.5, color: "#6D8FBC" },
              { offset: 1, color: "#3C516E" }
            ])
          }
        },
      },
      {
        name: '湿度',
        symbol: 'none',
        type: 'line',
        yAxisIndex: 1,
        data: humData,
        color: '#FFB401',
        lineStyle: {
          color: '#FFB401',
          width: 3
        },
      }
    ]
  }
  return option
}